﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;
using University.Workshop.Model;

namespace University.Workshop.WinApp
{
    public partial class AgendaDoctor : Form
    {
        public static bool validButton = false;              
        public static string format = "MMMMMMMMMM ";
        private string dateOne = DateTime.Now.ToShortDateString();
        private string dateTwo = DateTime.Now.AddDays(1).ToShortDateString();
        public DateTime nowDateTime = DateTime.Today;  
        private DateTime dateTomorrow = DateTime.Now.AddDays(1);
        Patient patient = new Patient();
        Manager doctor = new Manager();
        //Agenda agenda = new Agenda();
        Appointment appointment = new Appointment();
        string ciUser;
        
        public AgendaDoctor()
        {
            InitializeComponent();
            viewOrange(nowDateTime);
            viewBlue(dateTomorrow);
            ciUser = Main.userMenu[3];
            LoadAgendaToDate();
            //IssuePermits();
        }

        //private void IssuePermits()
        //{
        //    buttonNewAppointment.Enabled = RoleManager.PermissionUser(Main.userMenu[3], "NewAppointment");
        //}
        private void buttonNewAppointment_Click(object sender, EventArgs e)
        {
            NewAppointment appointment = new NewAppointment();
            appointment.ShowDialog();
        }
        public void LoadAgendaToDate()
        {
            dataGridViewToDayOrangue.DataSource = AgendaManager.LoadDataGridViewHorary(dateOne,ciUser);
            dataGridViewTomorrowBlue.DataSource = AgendaManager.LoadDataGridViewHorary(dateTwo,ciUser);
        }

        public void viewOrange(DateTime vo)
        {   
            textBoxOrange.Text = vo.DayOfWeek.ToString();
            textBoxDay1.Text = vo.Day.ToString();
            textBoxMonth1.Text = vo.ToString(format);
            textBoxYear1.Text = vo.Year.ToString();
        }
        public void viewBlue(DateTime vb)
        {
            textBoxBlue.Text = vb.DayOfWeek.ToString();
            textBoxDay2.Text = vb.Day.ToString();
            textBoxMonth2.Text = vb.ToString(format);
            textBoxYear2.Text = vb.Year.ToString();
        }
  
        public void fecAnt(DateTime fa,DateTime fs)
        {
            if (validButton == true)
            {              
                fa = fa.AddDays(-1);
                fs = fs.AddDays(-1);               
                nowDateTime = fa;
                dateTomorrow = fs;
                viewOrange(fa);
                viewBlue(fs);
                validButton = false;      
            }
            dateTwo = dateOne;
            dateOne = fa.ToShortDateString();
            LoadAgendaToDate();
        }
        public void fecSig(DateTime fa, DateTime fs)//nowDateTime
        {
            if (validButton == true)
            {
                fs = fs.AddDays(1);
                fa = fa.AddDays(1);                
                viewOrange(fa);
                viewBlue(fs);                
                nowDateTime = fa;
                dateTomorrow = fs;
                validButton = false;
            }
            dateOne = dateTwo;
            dateTwo = fs.ToShortDateString();
            LoadAgendaToDate();
        }
        private void buttonAnt_Click(object sender, EventArgs e)
        {
            validButton = true;
            fecAnt(nowDateTime,dateTomorrow);
        }

        private void buttonSig_Click(object sender, EventArgs e)
        {
            validButton = true;
            fecSig(nowDateTime, dateTomorrow);
        }

        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
            nowDateTime = this.monthCalendar1.SelectionEnd;
            dateTomorrow = nowDateTime.AddDays(1);
            dateOne = nowDateTime.ToShortDateString();
            dateTwo = dateTomorrow.ToShortDateString();
            LoadAgendaToDate();
            viewOrange(nowDateTime);
            viewBlue(dateTomorrow);
            
        }

        private void dataGridViewToDayOrangue_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            LoadDataAgenda();
            //AgendaSelected = true;
        }

        private void LoadDataAgenda()
        {
            //textBoxTimeAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells["TimeAgenda"].Value.ToString();
            textBoxFirstNameAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells["FirstName"].Value.ToString();
            textBoxLastNameAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells["LastName"].Value.ToString();
            textBoxCiPatientAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells["CiPatient"].Value.ToString();
            textBoxCellPhoneAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells["CellPhone"].Value.ToString();
            textBoxPhoneAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells["Phone"].Value.ToString();
            textBoxEmailAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells["Email"].Value.ToString();
            textBoxTimeAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells[1].Value.ToString();
            textBoxDateAgendaManager.Text = dataGridViewToDayOrangue.CurrentRow.Cells["DateAgenda"].Value.ToString();
            textBoxDoctorAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells["CiDoctor"].Value.ToString();
            textBoxStateAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells["StateAgenda"].Value.ToString();
            //textBoxFullNameAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells[2].Value.ToString();
            //textBoxPhoneAgenda.Text = dataGridViewToDayOrangue.CurrentRow.Cells[3].Value.ToString();
            
            patient.FirstName = textBoxFirstNameAgenda.Text;
            patient.LastName = textBoxLastNameAgenda.Text;
            patient.CIPatient = textBoxCiPatientAgenda.Text;
            patient.CellPhone = int.Parse(textBoxCellPhoneAgenda.Text);
            patient.Phone = int.Parse(textBoxPhoneAgenda.Text);
            patient.Email = textBoxEmailAgenda.Text;

            doctor.CIManager = textBoxDoctorAgenda.Text;
            doctor.FirstName = "Victor Hugo";
            appointment .DateAppointment= textBoxTimeAgenda.Text;
            appointment.TimeAppointment= textBoxDateAgendaManager.Text;
            appointment.StateAppointment = textBoxStateAgenda.Text;

        }

        private void buttonExitAgenda_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonModifyAppointment_Click(object sender, EventArgs e)
        {
            ModifyAppointment modifyAppointment = new ModifyAppointment(patient, doctor, appointment);
            modifyAppointment.Show();
        }
    }
}

